Introduction to Cryptography
Introduction
Cryptography is about protecting information.
People have been hiding messages for thousands of years, from ancient generals to modern internet users.
This article explores:
- How simple ciphers work
- Why people invented more complex systems
- How ideas evolved into today’s digital security
- A variety of classical methods, including book ciphers
- The basic intuition behind modern cryptography
What Is Cryptography? A Gentle Overview
Cryptography helps us:
- Keep messages secret
- Verify identities
- Prevent tampering
- Communicate safely over insecure channels
Two broad eras:
- Classical cryptography — letters, paper, and hand‑made rules
- Modern cryptography — computers, large numbers, and algorithms
The Caesar Cipher: Shifting Letters, Shifting Meanings
The Caesar cipher shifts each letter by a fixed amount.
How it works:
- Choose a shift (e.g., 3)
- Replace each letter with the one that many steps ahead
- Wrap around at the end of the alphabet
Example with shift 3:
- A → D
- B → E
- C → F
- X → A
- Y → B
- Z → C
Why it’s important:
- Historically significant
- Easy to understand
- A perfect first example of a cipher
Why it’s weak:
- Only 26 possible shifts
- Easy to brute‑force
Substitution Ciphers: Swapping Letters With a Secret Key
A substitution cipher replaces each letter with another letter.
Key features:
- You create a “mapping” from plaintext letters to ciphertext letters
- The mapping must be kept secret
- There are many possible mappings (far more than Caesar shifts)
Strengths:
- Harder to guess than a simple shift
- Can look very scrambled
Weaknesses:
- Still preserves letter frequencies
- Vulnerable to statistical attacks
Transposition Ciphers: Rearranging Instead of Replacing
Instead of changing letters, a transposition cipher reorders them.
Examples:
- Writing the message in rows and reading by columns
- Cutting the message into blocks and shuffling them
Strengths:
- Keeps letter frequencies intact but hides structure
- Often used together with substitution
Weaknesses:
- Patterns can still leak through
- Usually not secure on their own
Example: The fixed columnar transposition cipher
Encryption
Given the text "Hello, World!", we write this row-by-row, in a grid with 3 columns:
We then read it column-by-column to get "Hl r!eoWll,od".
Decryption
Decryption is simply reversing the steps above:
- Write the text column-by-column
- Read row-by-row
Permutation keys
A permutation key is simply a reordering of the column indices in a columnar transposition cipher.
If you have $ n $ columns, the “natural” order is: $$0, 1, 2, 3, \dots n‑1$$ A permutation key is any rearrangement of these numbers, for example: $$2, 0, 3, 1$$ This tells the cipher:
- write the plaintext row‑wise into a grid
- read the columns in the order given by the permutation
So if the key is $[2,0,3,1]$, you read:
- column 2
- column 0
- column 3
- column 1
This is what makes the cipher actually keyed.
Without a permutation, the cipher is deterministic and predictable.
Double transposition
A double transposition cipher applies two columnar transpositions in sequence, each with its own permutation key.
It was used extensively in WWII because it’s surprisingly strong for a hand cipher.
How it works
- First transposition
- Write plaintext into a grid
- Read columns in the order of key 1
- Second transposition
- Take the output of step 1
- Write it into a new grid
- Read columns in the order of key 2
Why it’s powerful
A single transposition is easy to break with modern frequency analysis.
A double transposition is much harder because:
- the structure of the text is scrambled twice
- the second permutation destroys patterns left by the first
- the combined effect is a composition of permutations, which grows factorially
Book Ciphers: Using a Shared Text as the Key
A book cipher uses a publicly available book as the secret key.
How it works:
- Sender and receiver agree on a book and edition
- Each word (or letter) in the message is encoded by a reference to the book
- Common formats:
- Page–line–word (e.g., 57–12–4)
- Page–paragraph–sentence
- Word numbers
Advantages:
- No need to memorize a key
- The “key” is large and complex
- Hard to break without knowing the exact book
Disadvantages:
- Both parties must have the same edition
- If the book is discovered, the cipher collapses
- Slow to encode and decode
Fun fact:
- Book ciphers appear in spy novels and real espionage cases
Frequency Analysis and the Limits of Classical Ciphers
Languages have patterns.
In English, for example:
- E is common
- Q, X, Z are rare
- Common pairs include TH, ER, ON
Frequency analysis:
- Count how often each symbol appears
- Compare with known language statistics
- Infer likely substitutions
Why classical ciphers fail:
- They don’t hide these patterns
- Computers can analyze frequencies instantly
The Navajo Code Talkers: Language as Encryption
During World War II, the United States Marine Corps used Navajo speakers to create an unbreakable communication system.
This wasn’t a cipher in the usual mathematical sense — it was a code based on a language that was:
- Unwritten
- Extremely complex
- Known fluently by very few people outside the Navajo Nation
Why Navajo Was Chosen
Several features made Navajo ideal:
- Rarity — very few non‑Navajo people spoke or understood it
- Complex grammar — difficult for outsiders to learn
- No widely available dictionaries or teaching materials at the time
- Large vocabulary and flexible structure
These properties made it resistant to codebreaking techniques used by enemy cryptanalysts.
How the Code Worked
The system combined:
- Natural Navajo words
- Specially assigned meanings for military terms
- Alphabet substitutions using Navajo words
Examples (simplified for teaching):
- Birds might represent aircraft
- Fish might represent ships
- Navajo words for everyday objects could stand for letters
This created a double layer:
- You had to understand Navajo
- You had to know the special codebook meanings
Why It Was So Effective
- Traditional codebreaking relies on patterns, frequencies, and structure
- The Navajo system avoided predictable patterns
- Even if someone understood Navajo, they still wouldn’t know the military meanings
- Messages could be sent and decoded faster than many mechanical cipher machines
Impact
- Used in major battles, including Iwo Jima
- Messages were transmitted securely and rapidly
- The code was never broken during the war
The Birth of Modern Cryptography
Modern cryptography emerged when:
- Computers became widespread
- Communication moved online
- People needed stronger protection
Key developments:
- Mathematical definitions of security
- Algorithms based on hard problems
- Use of large numbers and structured randomness
Modern cryptography focuses on:
- Algorithms, not hand‑made tricks
- Keys, not secrecy of the method
- Provable difficulty, not obscurity
Public‑Key Cryptography: A Conceptual Introduction
Public‑key cryptography changed everything.
Basic idea:
- Everyone has a public key and a private key
- Public key: used to encrypt
- Private key: used to decrypt
- Knowing the public key does not reveal the private key
Why this works:
- Based on one‑way processes
- Easy to do in one direction
- Extremely hard to reverse
Examples of one‑way ideas:
- Multiplying large primes
- Raising numbers to powers (with special rules)
- Certain geometric or algebraic transformations
This allows:
- Secure communication with strangers
- Digital signatures
- Online commerce
Calculator
Caesar Cipher
- Encrypts and decrypts text using the caesar cipher.
encrypted = caesarCipher('Hello, World!', 3) caesarCipher(encrypted, -3)
Substitution Cipher
- Encrypts and decrypts text using a substitution cipher.
key = substitutionGenerateKey() encrypted = substitutionEncrypt("Hello, World!", key) substitutionDecrypt(encrypted, key)
Transposition Cipher
- Encrypts and decrypts text using a fixed columnar transposition cipher.
encrypted = fixedColumnarTranspositionEncrypt("Hello, World!", 3) fixedColumnarTranspositionDecrypt(encrypted, 3)
Exercises
Encode With a Caesar Cipher
Choose a shift between 1 and 10.
Encode the message:
MEET ME AT MIDNIGHT
Write down:
- Your chosen shift
- The encoded message
Break a Caesar Cipher by Brute Force
The following message was encoded with a Caesar cipher, but the shift is unknown:
WKLV LV D VHFUHW
Tasks:
- Try all possible shifts
- Identify which decoded version makes sense
- State the shift used
Frequency Analysis Warm‑Up
Here is a ciphertext created with a Caesar cipher:
KHOOR ZRUOG
Tasks:
- Count how often each letter appears.
- Try all possible shifts or use your intuition about common words.
- Find the plaintext message and the shift used.
Create Your Own Substitution Cipher
Design a substitution alphabet (a mapping from A–Z to A–Z).
Then:
- Encode a short sentence
- Swap papers with a partner (or imagine a partner)
- Try to decode each other’s messages
Break a Substitution Cipher
Decode the following message, which uses a simple substitution cipher:
UIJT JT B TFDSFU NFTTBHF
Hints:
- Look for common short words
- Try guessing common letters like E, T, A
- Think about patterns like double letters
Try a Transposition Cipher
Write the message:
THE TREASURE IS BURIED HERE
into a grid with 4 columns, filling rows left to right.
Then:
- Read the message column by column
- Write down the ciphertext
- Try reversing the process to decode it again
Break a Transposition Cipher
The following was encoded using a fixed columnar transposition (unknown number of columns):
LKNRHTEO D EROUET E
Try to reconstruct the original message by:
- Testing different column counts
- Looking for meaningful word fragments
Compare Cipher Strengths
For each of the following ciphers, write one sentence explaining how you might try to break it:
- Caesar cipher
- Substitution cipher
- Transposition cipher
- Book cipher